# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=peach
pkgver=3.0.202
pkgrel=3
groups=('blackarch' 'blackarch-fuzzer')
pkgdesc='A SmartFuzzer that is capable of performing both generation and mutation based fuzzing.'
arch=('x86_64' 'aarch64')
url=('http://peachfuzzer.com/')
license=('MIT')
depends=('mono' 'python2' 'giflib' 'gcc-libs')
source=("http://downloads.sourceforge.net/project/peachfuzz/Peach/3.1%20Nightly/peach-$pkgver-source.zip")
sha512sums=('cbebed85ee67f87d94f2d6eeae27752021d5c7ca')

prepare() {
  sed -i "s|'win32', 'linux', 'darwin'|'linux'|" \
    "build/config/doc.py"

  if [ "$CARCH" == i686 ]; then
    sed -i "s|'x86', 'x86_64'|'x86'|" \
      "build/config/linux.py"
  else
    sed -i "s|'x86', 'x86_64'|'x86_64'|" \
      "build/config/linux.py"
  fi
}

package() {
  python2 ./waf configure
  python2 ./waf build --variant=release
  python2 ./waf install --variant=release --destdir="$pkgdir/usr/share/$pkgname"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  if [ "$CARCH" == i686 ]; then
    mv "$pkgdir/usr/share/$pkgname/output/linux_x86_release/bin"/* \
      "$pkgdir/usr/share/$pkgname/"
  else
    mv "$pkgdir/usr/share/$pkgname/output/linux_x86_64_release/bin"/* \
      "$pkgdir/usr/share/$pkgname/"
  fi

  rm -rf "$pkgdir/usr/share/$pkgname/output"

cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
  exec mono /usr/share/$pkgname/$pkgname.exe "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

